** This do-file should create a graph (using Clarify) with predicted values across the range 
** of observed values in the data.

** If the graph seems too bumpy, you can try increasing the number of points at which a 
** reading is taken by increasing the value for the local variable "obs" below.  Because
** we're using the observed values in the data, though, we're dependent on the number of 
** different values we actually observe (i.e. if we were using demloi, there'd only 
** be 21 different values observed, no matter how many different percentiles we take 
** observations for).

** If you'd like to run more graphs, you can copy the first run to another do file
** and make relevant changes.  The only differences among the three runs now are the first 
** two setx commands, which will set the values for the variables we want to fix
** (others are left at their observed values), and the contents of the xtitle and
** saving options in the graph command.
*clear
*set mem 600m

*use dyadicdiff_042006.dta, clear /* change name to correct dataset if necessary */
set more off

*keep mzmidl yr* sysdemsd propdem dempower demloi regdiffi regsyssd regpropi regpowri logdist cntgdumy allydumy capratio capsum onemajor mzyr* dyadid

** Main model is below for reference:
** logit mzmidl demlocorr regdiffcorr regpropcorr propdemcorr logdist cntgdumy allydumy capratio onemajor mzyp mzyr*, cluster(dyadid)

local DV="mzmidl"
local mainvar="propdemcorr" /* replace with variable of interest */
local controls="demlocorr regdiffcorr regpropcorr logdist cntgdumy allydumy capratio onemajor mzyp mzyr*"
gen yr=1815+_n
replace yr=. if yr>2000
gen yrpropdem=.
forvalues i=1816/2000 {
qui sum propdem if year==`i'
qui replace yrpropdem=r(mean) if yr==`i'
}



estsimp logit `DV' `mainvar' `controls', cluster(dyadid)
setx median
gen preds=.
gen predshi=.
gen predslo=.
gen level=.
gen levelval=.

local mainvar="propdemcorr"
local yrmainvar="yrpropdem"
local i=1
forvalues lev=1/99 {
	di `lev'
	qui replace level=`lev' in `i'
	setx demlocorr 10 /* change to graph at other values for demloi */
	setx regdiffcorr 0 /* change to graph at other values for regdiffi */
	qui centile `yrmainvar', c(`lev')
	local hi=r(c_1)
	qui replace levelval=`hi' in `i'
	setx (`mainvar') `hi'
	setx regpropcorr `hi'*0 /* remember to change! */
	simqi, genpr(ev)
	qui sumqi ev
	qui replace predslo=r(r1) in `i'
	qui replace predshi=r(r2) in `i'
	qui sum ev
	qui replace preds=r(mean) in `i' 
	drop ev
	local i=`i'+1
}

replace preds=1-preds
replace predslo=1-predslo
replace predshi=1-predshi

save ddp_graphdata_2, replace

capture label drop actual
forvalues i=10(20)90 {
centile yrpropdem, c(`i')
local val=round(r(c_1),.01)
label define actual `i' "`val'", add
}
label values level actual

#del ;
twoway (line preds level, lc(black)) (line predshi level, lc(gs12) lp(shortdash)) 
(line predslo level, lc(gs12) lp(shortdash)), graphregion(fcolor(white) )
ytitle("Probability of a Dispute") xtitle("Proportion of the System Democratic" 
"Both Countries Democratic") xlabel(10 30 50 70 90, valuelabel) ylabel(0(.0002).0008)
legend(off);

#del cr;
graph save response_predict_propdem.eps

label drop actual
